﻿#include "DecoObject.h"
#include "../MirEnvir/Envir.h"
#include "../../Shared/ServerPackets.h"

using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects
{

    ObjectType DecoObject::getRace() const
    {
        return ObjectType::Deco;
    }

    std::string DecoObject::getName() const
    {
        return Name;
    }

    void DecoObject::setName(const std::string &value)
    {
        Name = value;
    }

    int DecoObject::getCurrentMapIndex() const
    {
        return CurrentMapIndex;
    }

    void DecoObject::setCurrentMapIndex(int value)
    {
        CurrentMapIndex = value;
    }

    Point *DecoObject::getCurrentLocation() const
    {
        return CurrentLocation;
    }

    void DecoObject::setCurrentLocation(Point *value)
    {
        CurrentLocation = value;
    }

    MirDirection DecoObject::getDirection() const
    {
        return Direction;
    }

    void DecoObject::setDirection(MirDirection value)
    {
        Direction = value;
    }

    unsigned short DecoObject::getLevel() const
    {
        return Level;
    }

    void DecoObject::setLevel(unsigned short value)
    {
        Level = value;
    }

    bool DecoObject::getBlocking() const
    {
        return false;
    }

    int DecoObject::getHealth() const
    {
        throw NotSupportedException();
    }

    int DecoObject::getMaxHealth() const
    {
        throw NotSupportedException();
    }

    void DecoObject::Process()
    {
        //Cell cell = CurrentMap.GetCell(CurrentLocation);
        //for (int i = 0; i < cell.Objects.Count; i++)
        //    ProcessDeco(cell.Objects[i]);
    }

    void DecoObject::SetOperateTime()
    {
        long long time = getEnvir()->getTime() + 2000;

        //if (TickTime < time && TickTime > Envir.Time)
        //    time = TickTime;

        if (OwnerTime < time && OwnerTime > getEnvir()->getTime())
        {
            time = OwnerTime;
        }

        if (ExpireTime < time && ExpireTime > getEnvir()->getTime())
        {
            time = ExpireTime;
        }

        if (PKPointTime < time && PKPointTime > getEnvir()->getTime())
        {
            time = PKPointTime;
        }

        if (LastHitTime < time && LastHitTime > getEnvir()->getTime())
        {
            time = LastHitTime;
        }

        if (EXPOwnerTime < time && EXPOwnerTime > getEnvir()->getTime())
        {
            time = EXPOwnerTime;
        }

        if (BrownTime < time && BrownTime > getEnvir()->getTime())
        {
            time = BrownTime;
        }

        for (int i = 0; i < ActionList.size(); i++)
        {
            if (ActionList[i]->Time >= time && ActionList[i]->Time > getEnvir()->getTime())
            {
                continue;
            }
            time = ActionList[i]->Time;
        }

        for (int i = 0; i < PoisonList.size(); i++)
        {
            if (PoisonList[i]->TickTime >= time && PoisonList[i]->TickTime > getEnvir()->getTime())
            {
                continue;
            }
            time = PoisonList[i]->TickTime;
        }

        for (int i = 0; i < Buffs.size(); i++)
        {
            if (Buffs[i]->ExpireTime >= time && Buffs[i]->ExpireTime > getEnvir()->getTime())
            {
                continue;
            }
            time = Buffs[i]->ExpireTime;
        }

        if (OperateTime <= getEnvir()->getTime() || time < OperateTime)
        {
            OperateTime = time;
        }
    }

    void DecoObject::Process(DelayedAction *action)
    {
        throw NotSupportedException();
    }

    bool DecoObject::IsAttackTarget(PlayerObject *attacker)
    {
        throw NotSupportedException();
    }

    bool DecoObject::IsAttackTarget(MonsterObject *attacker)
    {
        throw NotSupportedException();
    }

    int DecoObject::Attacked(PlayerObject *attacker, int damage, DefenceType type, bool damageWeapon)
    {
        throw NotSupportedException();
    }

    int DecoObject::Attacked(MonsterObject *attacker, int damage, DefenceType type)
    {
        throw NotSupportedException();
    }

    int DecoObject::Struck(int damage, DefenceType type)
    {
        throw NotSupportedException();
    }

    bool DecoObject::IsFriendlyTarget(PlayerObject *ally)
    {
        throw NotSupportedException();
    }

    bool DecoObject::IsFriendlyTarget(MonsterObject *ally)
    {
        throw NotSupportedException();
    }

    void DecoObject::ReceiveChat(const std::string &text, ChatType type)
    {
        throw NotSupportedException();
    }

    Packet *DecoObject::GetInfo()
    {
        S::ObjectDeco *tempVar = new S::ObjectDeco();
        tempVar->ObjectID = ObjectID;
        tempVar->Location = getCurrentLocation();
        tempVar->Image = Image;

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was used in a 'return' or 'throw' statement.
        return tempVar;
    }

    void DecoObject::ApplyPoison(Poison *p, MapObject *Caster, bool NoResist, bool ignoreDefence)
    {
        throw NotSupportedException();
    }

    void DecoObject::Die()
    {
        throw NotSupportedException();
    }

    int DecoObject::Pushed(MapObject *pusher, MirDirection dir, int distance)
    {
        throw NotSupportedException();
    }

    void DecoObject::SendHealth(PlayerObject *player)
    {
        throw NotSupportedException();
    }

    void DecoObject::Despawn()
    {
        MapObject::Despawn();
    }
}
